using SQLLog4net.Log;
using SQLRunnerDMO;
using SQLRunnerLib.Project;
using SQLRunnerLib.Runners;
using SQLServices.Log;
using SQLServices.Repository;
using SQLServices.Runners;

namespace SQLRunnerLib.Services
{
	/// <summary>
	/// The Service Container provides global services to the application.
	/// The following global services are provided:
	/// Logger, SQLConnection, PathItem and Runner
	/// </summary>
	public class ServiceContainer
	{
		private static IAppLogger _Logger;
		private static ISQLConnection _sqlConnection;

		public ServiceContainer(){}

		#region Properties section

		public static IMessageLogger Logger
		{
			get
			{
				checkLogger();
				return _Logger;
			}
		}

		public static IEventLogger EventLogger
		{
			get
			{
				checkLogger();
				return _Logger;
			}
		}

		public static ISQLConnection SQLConnection
		{
			get
			{
				checkSQLConn();
				return _sqlConnection;
			}
		}


		public static IPathItem CreatePathItem(string name, IPathItem prevNode)
		{
			return new PathItem(name, prevNode);
		}


		public static IRunner CreateRunner(SQLProject project)
		{
			return new Runner(project);
		}

		#endregion
		#region Private Static methods

		private static void checkLogger()
		{
			if ( _Logger == null )
			{
				_Logger = new Logger();
			}
		}

		private static void checkSQLConn()
		{
			if ( _sqlConnection == null )
			{
				_sqlConnection = new SQLConnection();
			}
		}
		
		#endregion

	}
}
